/**
 * caputurer.h
 */

#ifndef __CAPTURER_H__
#define __CAPTURER_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "scheme.h"

// NOTE: won't transmit, so need not pack(1)
typedef struct Capturer {
	char id;
	char timeSeg;	// for return checkbox status for client only
	char type;
	Scheme *pSchemeList;
	struct Capturer *pNext;
} Capturer;

/**
 * find Capturer by id
 * @param
 *		id		input	capture addr
 * @return
 *		Capturer pointer or NULL when not find
 */
Capturer *findCapturer(Capturer *pList, char id);

/**
 * generate Capturer, will alloc Capturer for storage,
 * and it's user's responsible to release Capturer
 * @param
 *		pType	output	record type, NULL will not get type
 *		pBuff	input	buffer pointer
 * @return
 *		Capturer pointer, NULL when error
 */
Capturer *allocCapturer(char *pType, char *pBuff);

/**
 * delete capturer
 * @param
 *		pCapturer	input	Capturer which will be delete
 */
static inline void freeCapturer(Capturer *pCapturer) {
	if (pCapturer != NULL) {
	freeSchemeList(pCapturer->pSchemeList);
	free(pCapturer);
	}
}

/**
 * delete capturer list
 * @param
 *		pList		input	Capturer list
 */
static inline void freeCapturerList(Capturer *pList) {
	Capturer *pCapturer = pList;
	Capturer *pNextCapturer = NULL;
	while (pCapturer != NULL) {
		pNextCapturer = pCapturer;
		freeCapturer(pCapturer);
		pCapturer = pNextCapturer;
	}
}

/**
 * process Capturer
 * @param
 *		ppList	input	Capturer list pointer of pointer(may modify list head pointer)
 *		pProcCapturer		input	need process Capturer
 */
void processCapturer(Capturer **ppList, Capturer *pProcCapturer);

/**
 * convert capturer to pBuff
 * @param
 *		pBuff	output	buffer pointer
 *		buffSize	input	buffer size
 *		pCapturer	input	Sensor pointer
 * @return
 *		buffer size, -1 when buffer is too small or error occur
 */
int capturerToBuff(char *pBuff, int buffSize, Capturer *pCapturer);

/**
 * print capturer
 * @param
 *		pTitle	input	title
 *		pBuff	input	buffer
 *		size		input	data size
 */
void printBuff(char *pTitle, char *pBuff, int size);

#ifdef __cplusplus
}
#endif

#endif	// __CAPTURER_H__

